import Data.List

type Map = [String]
type Step = (Int, Int)
type Position = (Int, Int)

parseInput :: String -> Map
parseInput = lines

getPoint :: Step -> Map -> Position -> Char
getPoint (right,_) inputMap (row,col) = 
    (cycle line) !! col
    where
        line = inputMap !! row

getPath :: Step -> Map -> [Char] 
getPath step@(right,down) inputMap = 
    map (getPoint step inputMap) positions
    where   
        mapSize = length inputMap

        rows = takeWhile (<mapSize) . iterate (+down) $ 0
        cols = [0,right..]
        positions = zip rows cols

countTree :: [Char] -> Int 
countTree = length . filter (=='#')

getTreeCount :: Map -> Step -> Int
getTreeCount inputMap step = countTree . getPath step $ inputMap

main :: IO ()
main = do
    input <- readFile "./input.txt"
    let inputMap = parseInput input
    print . product . map (getTreeCount inputMap) $ [(1,1),(3,1),(5,1),(7,1),(1,2)]